﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace HQWeb.Login
{
    public partial class EditPassWord : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            string newMD5Value;
            string oldMD5Value = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPW.Text.Trim(), "MD5").Substring(0, 18);
            Model.SysManage.T_PUB_USER userModel = new Model.SysManage.T_PUB_USER();
            BLL.SysManage.T_PUB_USER userBll = new BLL.SysManage.T_PUB_USER();
            userModel = userBll.GetModel(Convert.ToInt32(Session["USER_ID"]));
            if (userModel.PASSWORD == oldMD5Value)
            {
                if (this.txtNewPW1.Text.Trim() == this.txtNewPW2.Text.Trim())
                {
                    newMD5Value = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNewPW2.Text.Trim(), "MD5").Substring(0, 18);
                   // userModel.USER_SYMBOL = Convert.ToString(Session["USER_SYMBOL"]);
                    userModel.PASSWORD = newMD5Value;
                    userBll.Update(userModel);
                    HttpContext.Current.Response.Write("<script language=javascript>alert('密码修改成功');window.close();</script>");
                }
                else
                {
                 Universal.JS.Alert("新密码与确认密码不正确,请重新输入");
                }
            }
            else
            {
                Universal.JS.Alert("原始密码输入不正确(如果您忘记密码请与管理员联系)");
            }
        }
    }
}